package edu.uwosh.cs342.project4;

import java.io.IOException;
import java.util.List;
import java.util.Locale;

import android.content.Context;
import android.location.Address;
import android.location.Geocoder;

public class AddressHelper {
	
	public AddressHelper(){
		super();
	}//end constructor
	
	public List<Address> getAddressesFromName(Context context, String searchLocation) throws IOException{
		Geocoder geoCoder = new Geocoder(context, Locale.getDefault());
		return geoCoder.getFromLocationName(searchLocation, 10);
	}//end performGeocoding
	
	public List<Address> getAddressesFromLocation(Context context, Double latitude, Double longitude) throws IOException{
		Geocoder geoCoder = new Geocoder(context, Locale.getDefault());
		return geoCoder.getFromLocation(latitude, longitude, 10);
	}//end getAddressesFromLocation
	
	public String addressLineBuilder(Address address){
		String output = "";
		
		for (int i = 0; i < address.getMaxAddressLineIndex() + 1; i++){
			if (i != address.getMaxAddressLineIndex())
				output += address.getAddressLine(i) + ", ";
			else
				output += address.getAddressLine(i);
		}
		
		return output;
	}//end addressLineBuilder

}//end class
